import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateValidator = data => {
    const requiredFields = [];
    if(!data || !data.code)
        requiredFields.push(
            formatMessage({
                id: 'validator.code',
                defaultMessage: '编号'
            })
        );
    if(!data || !data.type)
        requiredFields.push(
            formatMessage({
                id: 'validator.type',
                defaultMessage: '类型'
            })
        );
    if(!data || !data.kind)
        requiredFields.push(
            formatMessage({
                id: 'validator.kind',
                defaultMessage: '类别'
            })
        );
    if(!data || !data.description)
        requiredFields.push(
            formatMessage({
                id: 'validator.description',
                defaultMessage: '描述'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
